<template>
  <div class="wrapper example4-container">
    <!-- 返回区域 -->
    <div
      class="back-box"
      @click="$router.go(-1)"
    >返回</div>

    <!-- 标题区域 -->
    <h1 class="title-box">4、reactive函数2</h1>

    <!-- 实例区域 -->
    <div class="example4-box">
      <h1>一个人的信息</h1>
      <h2>姓名：{{ person.name }}</h2>
      <h2>年龄：{{ person.age }}</h2>
      <h2>工作类型：{{ person.job.type }}</h2>
      <h2>工作薪水：{{ person.job.salary }}</h2>
      <h2>测试的数据c：{{ person.job.a.b.c }}</h2>
      <h2>爱好：{{ person.hobby }}</h2>
      <button @click="changeInfo">修改人的信息</button>
    </div>
  </div>
</template>

<script>
import { reactive } from 'vue';

export default {
  name: 'Example4',
  setup() {
    // 数据
    const person = reactive({
      name: '张三',
      age: 20,
      job: {
        type: '前端工程师',
        salary: '30K',
        a: {
          b: {
            c: 666
          }
        }
      },
      hobby: ['爬山', '听歌', '打游戏']
    });

    // 方法
    const changeInfo = () => {
      person.name = '李四';
      person.age = 35;
      person.job.type = '后端工程师';
      person.job.salary = '40K';
      person.job.a.b.c = 999;
      person.hobby[0] = '游泳';
    };

    return {
      person,
      changeInfo
    };
  }
};
</script>

<style lang="scss" scoped>
.example4-container {
  // 返回区域
  & > .back-box {
    width: 50px;
    height: 23px;
    line-height: 20px;
    text-align: center;
    background-color: #efefef;
    margin-bottom: 20px;
    font-size: 14px;
    border: 1px solid #767676;
    border-radius: 4px;
    cursor: pointer;
  }

  // 标题区域
  & > .title-box {
    margin-bottom: 30px;
  }

  // 实例区域
  & > .example4-box {
    & > h1 {
      margin-bottom: 20px;
    }
    & > h2 {
      margin-bottom: 20px;
    }
    & > button {
      cursor: pointer;
    }
  }
}
</style>
